package com.right.health.app.ui.advisory.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.magic.basic.adapter.BaseAbsAdapter;
import com.right.health.app.R;
import com.right.health.app.bean.DoctorBean;
import com.right.health.app.utils.GlideUtil;


public class MyDoctorAdapter extends BaseAbsAdapter<DoctorBean> {

    public MyDoctorAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView == null) {
            convertView = mInflater.inflate(R.layout.my_doctor_item, null);
            viewHolder = new ViewHolder();
            viewHolder.mHospitalTv = convertView.findViewById(R.id.tv_hospital);
            viewHolder.mTypeIv = convertView.findViewById(R.id.iv_type);
            viewHolder.mNameTv = convertView.findViewById(R.id.tv_name);
            viewHolder.contentImage = convertView.findViewById(R.id.iv_avatar);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        DoctorBean bean = mDataSource.get(position);
        if (!TextUtils.isEmpty(bean.getImageurl())) {
            Glide.with(mContext).load(bean.getImageurl()).apply(GlideUtil.getAvatarPlaceholder()).into(viewHolder.contentImage);
        }
        viewHolder.mNameTv.setText(bean.getDoctorname());
        if (TextUtils.equals(bean.getRoletype(),"1")){
            viewHolder.mTypeIv.setImageResource(R.mipmap.ic_find_doctor_identity_nurse);
        }else if (TextUtils.equals(bean.getRoletype(),"2")){
            viewHolder.mTypeIv.setImageResource(R.mipmap.ic_find_doctor_identity_doctor);
        }
        return convertView;
    }

    private class ViewHolder {
        public TextView mNameTv,mHospitalTv;
        public ImageView mTypeIv,contentImage;
    }
}
